@echo off
chcp 65001 > nul
setlocal EnableDelayedExpansion

rem 根据命令行参数判断是否为重启进程

rem 设置记录文件的路径和名称
set "process_ports_file=process_ports.txt"

rem 读取记录端口号的文件，并将端口号保存到数组中
set "index=0"
for /f "tokens=*" %%a in (%process_ports_file%) do (
    set /a "index+=1"
    set "port[!index!]=%%a"
)

rem 根据端口号查询到相应的进程ID，并终止进程
for /l %%i in (1,1,%index%) do (
    for /f "tokens=5" %%j in ('netstat -ano ^| findstr /r ":!port[%%i]!.*LISTENING"') do (
        echo 进程ID：%%j
        taskkill /f /pid %%j >nul 2>&1
    )
)
echo 进程终止完成！

if "%1"=="restart" (
echo - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
echo 准备重启进程
echo - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
%CD%/onekeyrun.bat
exit /b
)




endlocal
